package com.zhouxiaoge.security.validate.code.sms;

import com.zhouxiaoge.security.properties.SecurityProperties;
import com.zhouxiaoge.security.validate.code.ValidateCode;
import com.zhouxiaoge.security.validate.code.ValidateCodeGenerator;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 作者：周小哥
 * 时间：2018-10-16 09:50
 */
@Component("smsCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode generate(ServletWebRequest request) {
        String numeric = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
        System.out.println("生成验证码：" + numeric);
        return new ValidateCode(numeric, securityProperties.getCode().getSms().getExpireInt());
    }

    public SecurityProperties getSecurityProperties() {
        return securityProperties;
    }

    public void setSecurityProperties(SecurityProperties securityProperties) {
        this.securityProperties = securityProperties;
    }
}
